package com.lhkj.ct.meta.modules.gauge.model.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.lhkj.ct.base.utils.TemplateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * <p>
 * 常模设置
 * </p>
 *
 * @author jobob
 * @since 2023-10-17
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="TblScaleDimNorm对象", description="常模设置")
public class TblScaleDimNorm implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId
    @ApiModelProperty(value = "常模id")
    private String normId;

    @ApiModelProperty(value = "维度id")
    private String dimId;

    @ApiModelProperty(value = "常模名称")
    private String normName;

    @ApiModelProperty(value = "最小年龄")
    private Integer minAge;

    @ApiModelProperty(value = "最大年龄")
    private Integer maxAge;

    @ApiModelProperty(value = "性别")
    private String suitSex;

    @ApiModelProperty(value = "公式")
    private String formula;

    @ApiModelProperty(value = "最小分值")
    private BigDecimal minScore;

    @ApiModelProperty(value = "最小分值运算符")
    private String minOperator;

    @ApiModelProperty(value = "最大分值")
    private BigDecimal maxScore;

    @ApiModelProperty(value = "最大分值运算符")
    private String maxOperator;

    @ApiModelProperty(value = "说明")
    private String explanation;

    @ApiModelProperty(value = "建议")
    private String recommend;

    @ApiModelProperty(value = "排序")
    private Integer normSort;

    public String ageRanger() {
        String exp = "";
        if (null != minAge) {
            exp += minAge + "<=age";
        }
        if (null != maxAge) {
            if (StringUtils.isNotBlank(exp)) {
                exp += "&&age<=" + maxAge;
            } else {
                exp += "age<=" + maxAge;
            }
        }
        return exp;
    }

    public String scoreExp() {
        if (StringUtils.isNotBlank(this.formula)){
            return TemplateUtil.replaceTemplate(this.formula,"\\{\\{([^\\}]+)\\}\\}").replaceAll("[—【】]","");
        }
        String exp = "";
        if (null != minScore) {
            exp += String.valueOf(minScore) + minOperator + "Score";
        }
        if (null != maxScore) {
            if (StringUtils.isNotBlank(exp)) {
                exp += "&&Score"+maxOperator + maxScore;
            } else {
                exp += "Score" + maxOperator + maxScore;
            }
        }
        return exp;
    }
}
